package org.bwapi.bridge.model;

import java.util.List;

import org.apache.commons.collections15.Transformer;
import org.bwapi.bridge.swig.PositionVector;
import org.bwapi.bridge.swig.SWIGTYPE_p_std__vectorT_BWAPI__Position_t;
import org.bwapi.bridge.swig.bridge;
import org.cretz.swig.collection.NativeList;

/**
 * Position
 * 
 * @see <a href="http://code.google.com/p/bwapi/wiki/Misc#Position">Position</a>
 * 
 * @author Chad Retz
 */
public class Position {
	private static final Transformer<Position, org.bwapi.bridge.swig.Position> FROM = 
		new Transformer<Position, org.bwapi.bridge.swig.Position>() {
			@Override
			public org.bwapi.bridge.swig.Position transform(Position position) {
				return position.getPosition();
			}
		};
		
	private static final Transformer<org.bwapi.bridge.swig.Position, Position> TO = 
		new Transformer<org.bwapi.bridge.swig.Position, Position>() {
			@Override
			public Position transform(org.bwapi.bridge.swig.Position position) {
				return new Position(position);
			}
		};

	public static final Position INVALID = new Position(bridge.getPositionInvalid());
	public static final Position NONE = new Position(bridge.getPositionNone());
	public static final Position UNKNOWN = new Position(bridge.getPositionUnknown());
	
	static List<Position> newList(SWIGTYPE_p_std__vectorT_BWAPI__Position_t nativeList) {
		return new NativeList<Position, org.bwapi.bridge.swig.Position>(
				org.bwapi.bridge.swig.Position.class, nativeList, PositionVector.class, 
				FROM, TO);
	}

	private final org.bwapi.bridge.swig.Position position;
	
	Position(org.bwapi.bridge.swig.Position position) {
		this.position = position;
	}

	public Position() {
		this(new org.bwapi.bridge.swig.Position());
	}

	public Position(TilePosition position) {
		this(new org.bwapi.bridge.swig.Position(position.getPosition()));
	}

	public Position(int x, int y) {
		this(new org.bwapi.bridge.swig.Position(x, y));
	}
	
	org.bwapi.bridge.swig.Position getPosition() {
		return position;
	}

	public boolean opEquals(Position position) {
		return this.position.opEquals(position.getPosition());
	}

	public boolean opNotEquals(Position position) {
		return this.position.opNotEquals(position.getPosition());
	}

	public boolean opLessThan(Position position) {
		return this.position.opLessThan(position.getPosition());
	}

	public Position opPlus(Position position) {
		return new Position(this.position.opPlus(position.getPosition()));
	}

	public Position opMinus(Position position) {
		return new Position(this.position.opMinus(position.getPosition()));
	}

	public Position opAdd(Position position) {
		return new Position(this.position.opAdd(position.getPosition()));
	}

	public Position opSubtract(Position position) {
		return new Position(this.position.opSubtract(position.getPosition()));
	}

	public double getDistance(Position position) {
		return this.position.getDistance(position.getPosition());
	}

	public double getLength() {
		return position.getLength();
	}
	
	//TODO: add util to set int from pointer

	public int x() {
		return position.xConst();
	}

	public int y() {
		return position.yConst();
	}
}
